﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using EvincePayroll.Data;
using EvincePayroll.Logic;
using EvincePayroll.Utility;
using System.Configuration;

namespace Evince.Service
{
    // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
    // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
    // a single instance of the service to process all calls.	
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    // NOTE: If the service is renamed, remember to update the global.asax.cs file
    public class AccountService
    {
        string userEmailId = ConfigurationManager.AppSettings["LoginID"].ToString();
        [WebGet(UriTemplate = "AuthenticateLogin/{emailId},{password}")]
        public bool AuthenticateLogin(string emailId, string password)
        {
            try
            {
                EmployeeLogic employeeLogic = new EmployeeLogic(emailId);
                return employeeLogic.AuthenticateLogin(emailId, password);
                //return false;
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "AuthenticateEmail/{emailId}")]
        public bool AuthenticateEmail(string emailId)
        {
            try
            {
                EmployeeLogic employeeLogic = new EmployeeLogic(emailId);
                return employeeLogic.AuthenticateEmail(emailId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "Logout/{emailId}")]
        public bool Logout(string emailId)
        {
            try
            {
                EmployeeLogic employeeLogic = new EmployeeLogic(userEmailId);
                return employeeLogic.Logout(emailId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebInvoke(UriTemplate = "RegisterEmployee/{emailId}")]
        public List<EmployeeData> RegisterEmployee(EmployeeData employeeData, string emailId)
        {
            try
            {
                EmployeeLogic employeeLogic = new EmployeeLogic(userEmailId);
                return employeeLogic.RegisterEmployee(employeeData);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        [WebGet(UriTemplate = "CheckExistingUser/{emailId}")]
        public bool CheckExistingUser(string emailId)
        {
            try
            {
                RegisterLogic registerLogic = new RegisterLogic(userEmailId);
                return registerLogic.CheckExistingUser(emailId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }


        [WebGet(UriTemplate = "GetAttendanceAdmin/{emailId},{fromDate},{toDate}")]
        public List<AttendanceData> GetAttendanceAdmin(string emailId, string fromDate, string toDate)
        {
            try
            {
                AttendanceLogic attendanceLogic = new AttendanceLogic(emailId);
                return attendanceLogic.GetAttendanceAdmin(emailId, fromDate, toDate);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "MarkAubsent")]
        public bool MarkAubsent()
        {

            try
            {
                LeaveRequstLogic leaveLogic = new LeaveRequstLogic(userEmailId);
                return leaveLogic.MarkAubsent();
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }


        }

        [WebGet(UriTemplate = "CheckOut/{emailId},{reason}")]
        public bool CheckOut(string emailId, string reason)
        {

            try
            {
                LeaveRequstLogic leaveLogic = new LeaveRequstLogic(emailId);
                return leaveLogic.CheckOut(emailId, reason);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }


        }

        [WebGet(UriTemplate = "CheckIn/{emailId}")]
        public bool CheckIn(string emailId)
        {

            try
            {
                LeaveRequstLogic leaveLogic = new LeaveRequstLogic(emailId);
                return leaveLogic.CheckIn(emailId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebInvoke(UriTemplate = "GetUpdatePassword/{email}")]
        public bool GetUpdatePassword(EmployeeData empdata, string email)
        {
            try
            {
                EmployeeLogic empLogic = new EmployeeLogic(email);
                return empLogic.GetUpdatePassword(empdata, email);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }


        }

        [WebGet(UriTemplate = "GetOnlineUsers/{emailId}")]
        public List<EmployeeData> GetOnlineUsers(string emailId)
        {
            try
            {
                EmployeeLogic emp = new EmployeeLogic(emailId);
                return emp.GetOnlineUsers(emailId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "GetMenuList/{emailId},{roleId}")]
        public List<MenuTableData> GetMenuList(string emailId, string roleId)
        {
            try
            {
                UserRoleLogic userRoleLogic = new UserRoleLogic(emailId);
                return userRoleLogic.GetMenuList(emailId, roleId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }

        [WebInvoke(UriTemplate = "DynamicMenu/")]
        public List<DynamicMenu> DynamicMenu(EmployeeData employeeData)
        {
            try
            {
                UserRoleLogic userRoleLogic = new UserRoleLogic(employeeData.Email);
                return userRoleLogic.DynamicMenu(employeeData);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        [WebInvoke(UriTemplate = "CreateMenuList/{email}")]
        public bool CreateMenuList(MenuTableData menuTableData, string email)
        {
            try
            {
                UserRoleLogic userRoleLogic = new UserRoleLogic(email);
                return userRoleLogic.CreateMenuList(menuTableData, email);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        [WebGet(UriTemplate = "DeleteMenu/{menuId}")]
        public bool DeleteMenu(string menuId)
        {
            try
            {
                UserRoleLogic userRoleLogic = new UserRoleLogic(menuId);
                return userRoleLogic.DeleteMenu(menuId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }




    }
}